function getRandomColor() {
  const rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length === 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}
const service = require('../../../service/mycard')
//import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast";

Page({
  onShareAppMessage() {
    return {
      title: 'video',
      path: 'page/component/pages/video/video',
      src: '',
      cardId: "",
      info: {},
      previewImg: [],
      legalname: "",
      sourceid: "",
      showmore:false,
      btntext:"查看更多企业信息"
    }
  },

  onLoad(options) {
    console.log(options)
    this.setData({
      cardId: options.id,
      sourceid: options.custId
    })

    service.insertcard({
      "cutomerIda": options.custId,
      "cardId": options.id
    }, res => {
      console.log(res)
    })
    //  this.data.cardId = "8845a13cea474edaa04348909030db48"
    service.getCardDetail(this.data.cardId, res => {
      console.log(res)
      var imglist = []
      for (let i = 0; i < res.data.businesscardPicList.length; i++) {
        const element = res.data.businesscardPicList[i];
        imglist.push(element.picUrl);
        this.setData({
          previewImg: imglist
        })
      }
      this.setData({
        info: res.data,
        legalname: res.data.name.substr(0, 1)
      })

    })
  },
  showmoreevent(){
    this.setData({
      showmore:!this.data.showmore
    })
    if(this.data.showmore==true){
      this.setData({
        btntext:"收起"
      })
    }else{
      this.setData({
        btntext:"查看更多企业信息"
      })
    }
  },
  onReady() {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  moreimgTo(e) {
    console.log('111')
  },
  previewImg: function (e) {
    console.log(e.currentTarget.dataset.index);
    //图片预览
    wx.previewImage({
      current: e.currentTarget.dataset.index, // 当前显示图片的http链接
      urls: e.currentTarget.dataset.urls
    })
  },
  onHide() {

  },

  inputValue: '',
  data: {
    src: '',
    showmore:false,
      btntext:"查看更多企业信息"
  },

  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },

  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },
  gostore() {
    wx.switchTab({
      url: '/pages/home/home'
    })
  },
  bindVideoEnterPictureInPicture() {
    console.log('进入小窗模式')
  },

  bindVideoLeavePictureInPicture() {
    console.log('退出小窗模式')
  },

  bindPlayVideo() {
    console.log('1')
    this.videoContext.play()
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },

  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },
  godetail(){
    wx.navigateTo({
      url: '/pages/mycard/detail/index?cardId=' + this.data.cardId,
    })
  }
})